﻿using System;
using System.Collections;
using Alserve.Ffl.Data;


namespace Alserve.Ffl
{
    public class ImportedMatch:IComparable
    {
        private Int32 _matchId = -1;
        private Int32 _espnMatchId = -1;
        private DateTime _matchDate = new DateTime(1900, 1, 1);
        private Int32 _homeClubId = -1;
        private Int32 _homeClubEspnId = -1;
        private String _homeClub = String.Empty;
        private Int32 _homeGoals = 0;
        private Int32 _awayClubId = -1;
        private Int32 _awayClubEspnId = -1;
        private String _awayClub = String.Empty;
        private Int32 _awayGoals = 0;
        private Int32 _competitionId = -1;
        private ArrayList _playerList = null;

        public ImportedMatch()
        {
        }

        public Int32 MatchId
        {
            get { return _matchId; }
            set { _matchId = value; }
        }

        public Int32 EspnMatchId
        {
            get { return _espnMatchId; }
            set { _espnMatchId = value; }
        }

        public DateTime MatchDate
        {
            get { return _matchDate; }
            set { _matchDate = value; }
        }

        public Int32 HomeClubId
        {
            get { return _homeClubId; }
            set 
            { 
                _homeClubId = value;
                Club thisClub = new Club();
                thisClub.Where.Id.Value = _homeClubId;
                if (thisClub.Query.Load())
                    _homeClub = thisClub.ClubName;
            }
        }

        public Int32 HomeClubEspnId
        {
            get { return _homeClubEspnId; }
            set
            {
                _homeClubEspnId = value;
                
                EspnClub thisEspnClub = new EspnClub();
                thisEspnClub.Where.EspnClubId.Value = _homeClubEspnId;
                if (thisEspnClub.Query.Load())
                {
                    _homeClubId = thisEspnClub.ClubId;
                    Club thisClub = new Club();
                    if (thisClub.LoadByPrimaryKey(_homeClubId))
                    {
                        _homeClub = thisClub.ClubName;
                    }
                }
            }
        }


        public String HomeClub
        {
            get { return _homeClub; }
        }

        public Int32 HomeGoals
        {
            get { return _homeGoals; }
            set { _homeGoals = value; }
        }

        public Int32 AwayClubId
        {
            get { return _awayClubId; }
            set
            {
                _awayClubId = value;
                Club thisClub = new Club();
                thisClub.Where.Id.Value = _awayClubId;
                if (thisClub.Query.Load())
                    _awayClub = thisClub.ClubName;

            }
        }

        public Int32 AwayClubEspnId
        {
            get { return _awayClubEspnId; }
            set
            {
                _awayClubEspnId = value;

                EspnClub thisEspnClub = new EspnClub();
                thisEspnClub.Where.EspnClubId.Value = _awayClubEspnId;
                if (thisEspnClub.Query.Load())
                {
                    _awayClubId = thisEspnClub.ClubId;
                    Club thisClub = new Club();
                    if (thisClub.LoadByPrimaryKey(_awayClubId))
                    {
                        _awayClub = thisClub.ClubName;
                    }
                }
            }
        }

        public String AwayClub
        {
            get { return _awayClub; }
        }

        public Int32 AwayGoals
        {
            get { return _awayGoals; }
            set { _awayGoals = value; }
        }

        public Int32 CompetitionId
        {
            get { return _competitionId; }
            set { _competitionId = value; }
        }

        public ArrayList PlayerList
        {
            get { return _playerList; }
            set { _playerList = value; }
        }

        public int CompareTo(object obj)
        {
            ImportedMatch thisImportedMatch = (ImportedMatch)obj;

            if (this.MatchDate == thisImportedMatch.MatchDate)
                return this.HomeClubId.CompareTo(thisImportedMatch.HomeClubId);
            else
                return -(this.MatchDate.CompareTo(thisImportedMatch.MatchDate));
        }

    }
}